package hasthi.container.p2p;
import hasthi.common.XmlBeanUtils;

import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.w3.x2003.x05.soapEnvelope.EnvelopeDocument;

import rice.p2p.commonapi.Id;
import rice.p2p.scribe.ScribeContent;



public class MulticastXmlMessage  extends XmlMesssage implements ScribeContent {
    private static final long serialVersionUID = 391984647176983694L;

    public MulticastXmlMessage(){}
    
    public MulticastXmlMessage(EnvelopeDocument envelope) {
        super(envelope);
    }


    public MulticastXmlMessage(XmlObject message, Id senderID, String soapAction) {
        super(message, senderID, soapAction);
    }


    public String toString() {
      return XmlBeanUtils.prettyPrint(envelope);
    }  
    
    
    private void writeObject(java.io.ObjectOutputStream out)throws IOException{
        envelope.save(out);
    }
    private void readObject(java.io.ObjectInputStream in)throws IOException, ClassNotFoundException{
        try {
            this.envelope = (EnvelopeDocument)XmlObject.Factory.parse(new InputStreamReader(in));
            XmlCursor c = envelope.getEnvelope().getHeader().newCursor();
            headers = XmlBeanUtils.extractProperties(c,true);
            c.dispose();
        } catch (XmlException e) {
           throw new IOException(e.getMessage());
        }
    }

}

